<template>
  <div>
    <p-form-model :model="form" :rules="rules" layout="inline">
      <p-form-model-item label="商机编号">
        <p-input v-model="form.opportunityNo" placeholder="请输入" />
      </p-form-model-item>
      <p-form-model-item label="商机名称">
        <p-input v-model="form.opportunityName" placeholder="请输入" />
      </p-form-model-item>
      <p-form-model-item label="客户简称">
        <p-input v-model="form.customerShortName" placeholder="请输入" />
      </p-form-model-item>
      <p-form-model-item label="销售组织">
        <SelectOrg v-model="form.salesOrgCode" />
      </p-form-model-item>
      <p-button type="primary" class="btn-search" @click="handleSearch">
        搜索
      </p-button>
      <p-form-model-item label="商机状态">
        <SelectDefault v-model="form.state" code="business_status" />
      </p-form-model-item>
      <p-form-model-item label="商机阶段">
        <SelectDefault
          v-model="form.stage"
          code="business_stage_process_node"
        />
      </p-form-model-item>
      <p-form-model-item label="当前处理人">
        <p-input v-model="form.handleUserName" placeholder="请输入" />
      </p-form-model-item>
      <p-form-model-item label="创建时间">
        <p-range-picker
          v-model="form.creatTime"
          :placeholder="['开始时间', '结束时间']"
          format="YYYY-MM-DD"
          :mode="mode"
          :value="value"
          @change="changeTime"
        />
      </p-form-model-item>
      <p-button style="margin-right: 20px" @click="handleReset">重置</p-button>
      <p-button @click="handleexport">导出</p-button>
    </p-form-model>
  </div>
</template>
<script>
import monent from 'moment';
const defaultForm = {
  opportunityNo: undefined,
  opportunityName: undefined,
  customerShortName: undefined,
  salesOrgCode: undefined,
  state: undefined,
  stage: undefined,
  handleUserName: undefined,
  creatTime: undefined,
  startCreateTime: undefined,
  endCreateTime: undefined,
};
export default {
  data() {
    return {
      form: {
        ...defaultForm,
        mode: ['date', 'date'],
        value: [],
      },
    };
  },
  methods: {
    handleSearch() {
      this.$emit('search', this.form);
    },
    handleReset() {
      this.form = { ...defaultForm };
      this.$emit('search', this.form);
    },
    handleexport() {
      this.$emit('export');
    },
    changeTime(value) {
      this.value = value;
      this.form.startCreateTime =
        monent(value[0]).format('YYYY-MM-DD') + ' ' + '00:00:00';
      this.form.endCreateTime =
        monent(value[1]).format('YYYY-MM-DD') + ' ' + '23:59:59';
    },
  },
};
</script>

<style lang="less" scoped>
.poros-form {
  box-sizing: border-box;
  background-color: #f7f7f8;
  padding: 10px;
  padding-bottom: 0px;
  width: 100%;
}
.poros-form-item {
  width: 20%;
  margin-bottom: 10px;
}
/deep/ .poros-form-item-control-wrapper {
  width: calc(100% - 70px);
}
.btn-search {
  margin-right: 16px;
}
/deep/ .poros-form-item-label {
  width: 70px;
}
</style>
